package com.easybuy.dao.impl;

import com.easybuy.dao.UserAdressDao;
import com.easybuy.entity.UserAddress;
import com.easybuy.utils.BaseDao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
//import java.text.SimpleDateFormat;
//import java.util.Date;






public class UserAddressDaoImpl extends BaseDao implements UserAdressDao {


	public List<UserAddress> getUserAddresses(int userId) {
		List<UserAddress> addressList=new ArrayList<UserAddress>();
		String sql="select * from easybuy_user_address where userId=?";
		
		try {
			prestmt=this.connectMysql().prepareStatement(sql);
			prestmt.setInt(1, userId);
			rs=prestmt.executeQuery();
			while(rs.next()){
//				if(rs.getDate("createTime")!=null){
//					address.setCreateTime(rs.getDate("createTime"));
//				}
//				int Id=rs.getInt("userId");
//				Date date=rs.getDate("createTime");
//				String addr=rs.getString("address");
//				int isDefault= rs.getInt("isDefault");
//				String remark=rs.getString("remark");
//				address.setUserId(Id);
//				address.setAddress(addr);
//				new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date());
//				address.setCreateTime(new java.util.Date());
//				address.setIsDefault(isDefault);
//				address.setRemark(remark);
//				System.out.println(address.getUserId());
//				addressList.add(address);
				addressList.add(new UserAddress(rs.getInt("userId"), rs.getString("address"), rs.getDate("createTime"), rs.getInt("isDefault"), rs.getString("remark")));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return addressList;
	}

	public int changeDefault(int isDefault){
		return isDefault;
		
	}
	
}
